// How Many Tables
#include <iostream>
using namespace std;

int set[1001];

int find(int r)
{
    while(set[r] != r)
    {
        r = set[r];
    }
    return r;
}

void merge(int a, int b)
{
    int r1 = find(a);
    int r2 = find(b);
    if(r1 != r2)
    {
        set[a] = b;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int T, crowd, cases, man1, man2, tables;
    cin >> T;
    while(T--)
    {
        cin >> crowd >> cases;
        for(int i=1; i<=crowd; i++)
        {
            set[i] = i;
        }
        for(int i=1; i<=cases; i++)
        {
            cin >> man1 >> man2;
            merge(man1, man2);
        }
        tables = 0;
        for(int i=1; i<=crowd; i++)
        {
            if(set[i] == i)
            {
                tables++;
            }
        }
        cout << tables << endl;
    }
    return 0;
}